import 'package:boss/models/store_menu.dart';
import 'package:boss/provider/commodity_provider.dart';
import 'package:boss/textStyle/text_style.dart';
import 'package:boss/ui/page/commodity/categories/page/searchCommodity/search_commodity_provider.dart';
import 'package:boss/ui/widget/center_title_app_bar.dart';
import 'package:flutter/material.dart';
import 'package:hi_common/hi_common.dart';
import 'package:provider/provider.dart';
import 'package:router/annotation.dart';

import 'widget/search_commodity_browser.dart';

@RouterConfig(SearchCommodityPage.pageName)
class SearchCommodityPage extends StatefulWidget {
  static const pageName = '/searchCommodityPage';

  @Autowired()
  final List<StoreMenu> menus;

  const SearchCommodityPage(this.menus);

  @override
  _SearchCommodityPageState createState() => _SearchCommodityPageState('搜索菜品');
}

class _SearchCommodityPageState extends BaseState<SearchCommodityPage> {
  _SearchCommodityPageState(String pageName) : super(pageName);

  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => SearchCommodityProvider(widget.menus),
      child: Scaffold(
        appBar: CenterTitleAppBar(
          title: Consumer<CommodityProvider>(
            builder: (context, commodityProvider, child) {
              return RichText(
                text: TextSpan(
                  text: '全部菜品',
                  style: TextStyleConstant().normal_1_36,
                  children: [
                    TextSpan(
                      text: '(${commodityProvider.allCommodityCount})',
                      style: TextStyleConstant().normal_2_26,
                    ),
                  ],
                ),
              );
            },
          ),
        ),
        body: SearchCommodityBrowser(),
      ),
    );
  }
}

Future searchCommodity(BuildContext context, List<StoreMenu> menus) {
  return Navigator.pushNamed(context, SearchCommodityPage.pageName, arguments: {'menus': menus});
}
